<?php
namespace app\admin\controller;
class Carousel 
{
	public function __construct(){
		Admin_auth();
	}
	
    public function index()
    {
		$cid = input('get.cid');
		if(!empty($cid)){
			$where = ['cid'=>$cid];
		}else{
			$where = "";
		}
		$pages = pages('carousel',$where,input('get.page'));
		$data = db("carousel")->where($where)->whereIn('pid',session('wmo2o_a_pid'))->limit($pages['limit'])->order('id desc')->select();
        return view('',['data'  => $data,'pages' => $pages['pages']]);
    }
	
	public function edit()
    {
		$id = input("get.id")?input("get.id"):0;
		$data = array();
		if(request()->isPost()){
			$data = input("post.");
			if($id){
				db("carousel")->where(['id' => $id])->update($data);
				$data['id'] = $id;
			}else{
				$data['time'] = time();
				$data['id'] = db("carousel")->insertGetId($data);
			}
		}else{
			$data = db("carousel")->where(['id' => $id])->find();
		}
        return view('',['data'  => $data]);
    }
	
	public function del()
    {
		$id = input("get.id")?input("get.id"):0;
		$page = input("get.page");
		$data = db("carousel")->whereIn('pid',session('wmo2o_a_pid'))->delete($id);
		redirect(url('/admin/carousel?page='.$page));
		exit;
    }
}
